//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbTDChuyenMon
    {
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTDChuyenMon_SelectAll", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTDChuyenMon_SelectTop", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbTDChuyenMon OTbTDChuyenMon)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenTDChuyenMon", OTbTDChuyenMon.TenTDChuyenMon);
            pr[1] = new SqlParameter(@"TrangThai", OTbTDChuyenMon.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbTDChuyenMon_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbTDChuyenMon OTbTDChuyenMon)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaTDChuyenMon", OTbTDChuyenMon.MaTDChuyenMon);
            pr[1] = new SqlParameter(@"TenTDChuyenMon", OTbTDChuyenMon.TenTDChuyenMon);
            pr[2] = new SqlParameter(@"TrangThai", OTbTDChuyenMon.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbTDChuyenMon_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(int MaTDChuyenMon)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaTDChuyenMon",MaTDChuyenMon);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbTDChuyenMon_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbTDChuyenMon SelectByID(int MaTDChuyenMon)
        {
            ETbTDChuyenMon OTbTDChuyenMon = new ETbTDChuyenMon();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaTDChuyenMon",MaTDChuyenMon);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbTDChuyenMon_SelectByID", pr);
            if (idr.Read())
              OTbTDChuyenMon = GetOneTbTDChuyenMon(idr);
            idr.Close();
            idr.Dispose();
            return OTbTDChuyenMon;
        }
//-----------------------------------------------------------//
        private static ETbTDChuyenMon GetOneTbTDChuyenMon(IDataReader idr)
       {
            ETbTDChuyenMon OTbTDChuyenMon = new ETbTDChuyenMon();
                if (idr["MaTDChuyenMon"] != DBNull.Value)
                    OTbTDChuyenMon.MaTDChuyenMon = (int)idr["MaTDChuyenMon"];
                if (idr["TenTDChuyenMon"] != DBNull.Value)
                    OTbTDChuyenMon.TenTDChuyenMon = (string)idr["TenTDChuyenMon"];
                if (idr["TrangThai"] != DBNull.Value)
                    OTbTDChuyenMon.TrangThai = (int)idr["TrangThai"];
            return OTbTDChuyenMon;
       }
//-----------------------------------------------------------//
        public static bool TestByID(int MaTDChuyenMon)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaTDChuyenMon",MaTDChuyenMon);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbTDChuyenMon_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbTDChuyenMon> ListAll()
        {
            List<ETbTDChuyenMon> list = new List<ETbTDChuyenMon>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbTDChuyenMon_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbTDChuyenMon(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }

        public static List<ETbTDChuyenMon> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbTDChuyenMon> list = new List<ETbTDChuyenMon>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbTDChuyenMon_SelectAll", pr);
            while (idr.Read())
              list.Add(GetOneTbTDChuyenMon(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}